package com.bgs.controller;

import com.bgs.entity.Recyclingorder;
import com.bgs.entity.Store;
import com.bgs.entity.User;
import com.bgs.pojo.CommodityorderVo;
import com.bgs.service.RecyclingorderService;
import com.bgs.service.StoreService;
import com.bgs.service.UserService;
import com.bgs.tool.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("recyclingorder")
public class RecyclingorderController {
    @Autowired
    private RecyclingorderService recyclingorderService;
    @Autowired
    private StoreService storeService;
    @Autowired
    private UserService userService;
    //根据id查询店家
    @GetMapping("findshop")
    public  R findshop(String id){
         String[] a = id.split("-");
          String storeId = a[1];
        Store store1 = recyclingorderService.findshop(storeId);
        return R.ok().data("shop",store1);
    }
    // 查询全部店家位置
    @GetMapping("getallshop")
    public R getallshop(){
        List<Store> storeList = recyclingorderService.getallshop();
        return R.ok().data("shops",storeList);
    }

    //    根据状态查询回收订单
    @GetMapping("load/{curNow}/{userId}")
    public R load(@PathVariable Integer curNow ,@PathVariable Integer userId){

        List<Recyclingorder> recyclingorders =  recyclingorderService.load(curNow,userId);
        return R.ok().data("arr",recyclingorders);
    }
    //    取消回收订单
    @GetMapping("qxdd/{roId}")
    public R qxdd(@PathVariable Integer roId){
        recyclingorderService.qxdd(roId);
        return R.ok();
    }
    //    查询订单信息
    @GetMapping("find/{roId}")
    public R find (@PathVariable Integer roId){
        Map<String,Object> map = new HashMap<>();
        Recyclingorder recyclingorder = recyclingorderService.find(roId);
        List<Store> stores =  storeService.load2(recyclingorder.getStoreId());
        List<User> user = userService.load3(recyclingorder.getRiderId());
        map.put("recyclingorder",recyclingorder);
        map.put("store",stores);
        map.put("user",user);
        return R.ok().data("data",map);
    }
    //添加回收订单
    @PostMapping("addorder")
    public R addorder(@RequestBody Recyclingorder recyclingorder){
       recyclingorderService.addorder(recyclingorder);
      return  R.ok();
    }
}